

import os,inspect
import  run_main
import multiprocessing
from tools.AdbOperation import *
import requests
import pytest


configPath = os.path.join(pro_path, 'config.ini')
casePath = os.path.join(pro_path, 'testcase')



mode = Config.getRunparam(configPath,"mode")
apkurl =  Config.getRunparam(configPath,"apkurl")
reruns = Config.getRunparam(configPath,"reruns")
platform = Config.getRunparam(configPath,"platform")
buildNumber = Config.getRunparam(configPath,"buildNumber")
mark = Config.getRunparam(configPath,"mark")
reruns_delay = Config.getRunparam(configPath,"reruns_delay")
phone_list_str = Config.getRunparam(configPath,"phone_list")
phone_list =  phone_list_str.split(",")



#下载包
def downapk(url):
    r = requests.get(apkurl)
    with open("bangbangshizi.apk","wb") as code:
        code.write(r.content)



def CreatePool():
    adboperarion = AdbOperation()
    deviceslist =  adboperarion.getdevices()
    reportfilename = buildNumber
    if mode == "2":
        case_list = os.listdir(casePath)
        #case_list = ["test_L1BigMap_AllEntry.py","test_L1BigMap_EntryLeftInfo.py","test_L1BigMap_EntryParentCenter.py","test_L2BigMap_EntryParentCenter.py"]
        case_queue = multiprocessing.Queue()
        for case in case_list:
            if case != "__pycache__":
                case_queue.put(case)
        case_path_name = case_queue
    else:
        case_path_name = casePath
    pool = []
    for i in range(len(deviceslist)):
        device = deviceslist[i]
        if i > len(phone_list):
            print("账号已用完")
        phone = phone_list[i]
        print("--------一个进程---------")
        p = multiprocessing.Process(target=run_main.Runcase, args=(device, reportfilename, case_path_name,phone))
        p.start()
        pool.append(p)
    for p in pool:
        p.join()







if __name__ == '__main__':
    if apkurl != "":
        downapk(apkurl)
    CreatePool()

